/** 
 * @file:     calc.c
 * @Author:   ChenBlue
 * @email:    ChenBlue952@qq.com
 * @data:     Thu Jul 25 20:44:39 2024
 * @brief:   
 */

#include "adaptogui.h"
#include "lvgl/lvgl.h"
#include "lvgl/lv_lib.h"

static lv_obj_t * main_page; // APP 内的主页面

static void calc_exit(void)
{

}

static void calc_main(void)
{
	lv_calc_simple();
}

void calc_btn_cb(lv_event_t event)
{
	if (event.code == LV_EVENT_CLICKED) {
		lv_scr_load_anim(main_page, LV_SCR_LOAD_ANIM_OVER_LEFT, 0, 0, false);
		calc_main();
	}
}

static void return_btn(lv_event_t event)
{
	if (event.code == LV_EVENT_CLICKED) {
		lv_scr_load_anim(root_page, LV_SCR_LOAD_ANIM_OUT_RIGHT, 100, 0, false);
	}
}

int calc_init(void)
{
	main_page = lv_obj_create(NULL);
	lv_obj_set_size(main_page, LV_HOR_RES, LV_VER_RES);

	lv_obj_t * btn = lv_btn_create(main_page);
	lv_obj_set_pos(btn, 50, 50);
	lv_obj_set_size(btn, 50, 50);

	lv_obj_set_style_radius(btn, LV_PCT(25), LV_PART_MAIN);

	lv_obj_add_event_cb(btn, return_btn, LV_EVENT_ALL, NULL);
	return 0;
}

struct APP_OBJ calc_app = {"   calc", "calc.png", "ChenBlue", calc_init,
                            calc_btn_cb, calc_main, calc_exit};